package com.zh.kotlin_mvvm.ui

import android.content.res.Configuration
import android.os.Bundle
import com.xyz.livelib.manager.LiveManager
import com.zh.common.base.BaseActivity
import com.zh.kotlin_mvvm.databinding.ActivityLiveBinding

class LiveActivity : BaseActivity<ActivityLiveBinding>() {

    private val url = "rtmp://192.168.3.3:1936/live/gC2EqJE2?account=tste"

    override fun initView(savedInstanceState: Bundle?) {
        viewBinding.apply {
            etUrl.setText(url)
            LiveManager.getInstance().init(etUrl.text.toString(), camera)
            push.setOnClickListener {
                if (push.text.equals("停止")) {
                    push.text = "开始"
                    LiveManager.getInstance().stopLive()
                } else {
                    push.text = "停止"
                    LiveManager.getInstance().startLive()
                }
            }
            change.setOnClickListener {
                LiveManager.getInstance().changeCamera()
                LiveManager.getInstance().stopLive()
                it.postDelayed({
                    LiveManager.getInstance().startLive()
                }, 1)
            }
        }
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        viewBinding.camera.previewAngle(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        viewBinding.camera.onDestroy()
        LiveManager.getInstance().stopLive()
    }
}